angular.module('flow-div', [])

.directive 'flowDiv', ->
    restrict    : 'E'
    templateUrl : 'templates/flow-div/flow-div.html'
    scope:
        'items' : '=items'
        'itemClick':'=itemClick'
        'itemRefer':'=itemRefer'
        'itemOnHold':'=itemOnHold'
        'itemRerfer':'=itemRerfer'
    link: ($scope, $element, $attrs) ->

.controller 'flowDivCtrl', ($scope, $state,showToast, $ionicHistory,$localStorage,$ionicViewSwitcher,userData,$http,$ionicPopup) ->
    $scope.$storage = $localStorage
    _.extend $scope,
        goodsGetIn: (goodItem)->
            if goodItem.isadd == '0'
                if $ionicHistory.backView().stateName == 'tab.home'
                    $state.go 'tab.goods-addypk-home', {obj: goodItem}
                else if $ionicHistory.backView().stateName == 'tab.orders'
                    $state.go 'tab.goods-addypk-orders', {obj: goodItem}
                else if $ionicHistory.backView().stateName == 'tab.purchase'
                    $state.go 'tab.goods-addypk-purchase', {obj: goodItem}
                else
                    $state.go 'tab.goods-addypk', {obj:goodItem}
            else
                showToast '不能重复入库该商品'
        choose: (goodItem,e) ->
            e.stopPropagation()
            $localStorage['goodItem'] = goodItem
            $scope.itemClick($localStorage['goodItem'])
#            $state.go 'tab.market-detail',{item: goodItem}
        share: (item) ->
            if $scope.itemRefer
                $scope.itemOnHold(item)





